package com.ruoyi.business.controller;

import com.ruoyi.business.domain.CarPackageAudit;
import com.ruoyi.business.domain.DefinitionInfo;
import com.ruoyi.business.domain.ServiceItem;
import com.ruoyi.business.domain.StatementItem;
import com.ruoyi.business.service.ICarPackageAuditService;
import com.ruoyi.business.service.IProcessService;
import com.ruoyi.business.service.ITodoService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/business/todo")
public class TodoController extends BaseController {
    private String prefix = "business/task";

    @Autowired
    private ITodoService todoService;
    @Autowired
    private IProcessService processService;
    @Autowired
    private ICarPackageAuditService carPackageAuditService;

    @GetMapping("/serviceItem/edit")
    public String editList(Long carPackageAuditId,ModelMap map)
    {
        CarPackageAudit carPackageAudit = carPackageAuditService.selectCarPackageAuditById(carPackageAuditId);
        if (carPackageAudit == null){
            throw new BusinessException("审核记录不存在");
        }
        map.put("serviceItem", carPackageAudit.getServiceItem());
        map.put("carPackageAuditId", carPackageAuditId);
        //服务项对象
        return prefix + "/edit";
    }
    @GetMapping()
    public String carPackageAudit()
    {
        return prefix + "/todo";
    }

    /**
     * 查询审核列表列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CarPackageAudit carPackageAudit)
    {
        return todoService.selectTodoList(carPackageAudit);
    }

    /**
     * 显示审批页面
     * @param taskId 任务Id
     * @param mmap map
     * @return 视图
     */
    @RequestMapping("/showAuditDialog/{taskId}")
    public String showVerifyDialog(@PathVariable("taskId") String taskId, ModelMap mmap){
        mmap.put("taskId",taskId);
        return prefix+"/auditDialog";
    }

    /**
     * 审批任务
     */
    @Log(title = "审批任务", businessType = BusinessType.OTHER)
    @PostMapping("/complete/{taskId}")
    @ResponseBody
    public AjaxResult export(@PathVariable String taskId, boolean auditStatus,String comment)
    {
        todoService.taskAudit(taskId, auditStatus,comment);
        return success("审批完成");
    }

    /**
     * 修改服务项
     */
    @Log(title = "修改服务项", businessType = BusinessType.UPDATE)
    @PostMapping("/serviceItem/edit")
    @ResponseBody
    public AjaxResult editServiceItem(ServiceItem serviceItem, Long carPackageAuditId)
    {
        todoService.updateServiceItem(serviceItem, carPackageAuditId);
        return success("修改服务项完成");
    }
    /**
     * 重新申请
     */
    @Log(title = "重新申请", businessType = BusinessType.OTHER)
    @PostMapping("/reApply")
    @ResponseBody
    public AjaxResult reApply(String taskId, String carPackageAuditId)
    {
        todoService.reApply(taskId, carPackageAuditId);
        return success("重新申请成功");
    }
}
